#ifndef TASK_H_
#define TASK_H_

#include <uv.h>

/* Fully close a loop */
static void close_walk_cb(uv_handle_t* handle, void* arg) {
  if (!uv_is_closing(handle))
    uv_close(handle, NULL);
}

static void close_loop(uv_loop_t* loop) {
  uv_walk(loop, close_walk_cb, NULL);
  uv_run(loop, UV_RUN_DEFAULT);
}

#define MAKE_VALGRIND_HAPPY()           \
  do {                                  \
    close_loop(uv_default_loop());      \
    uv_loop_delete(uv_default_loop());  \
  } while (0)

#endif
